home *** CD-ROM | disk | FTP | other *** search
- // Button.lib - Work with button using SCREEN.LIB library
- // ver.1
- //
- //*** CreateButton() - initialize button structure
- // SYNTAX: struct CreateButton(string Text,int Row,int Col,int Height,int Width,
- // int ForeColor,int BackColor,
- // bool 3D,bool Lines)
- // WHERE: Text: String to print in middle of button
- // Row,Col: Starting row and column of button
- // Height,Width: button height and width, including lines but not shadow
- // ForeColor,BackColor: Foreground and background color of button
- // 3D: If true then push button (shadow), else inverse button
- // Lines: 0 for no line, else SINGLE_LINE or DOUBLE_LINE
- // NOTE: This function may move cursor, and looks at current screen color
- // to get background color if 3D. Does not change color
- //
- //*** PushButton() - Push selected button
- // SYNTAX: void PushButton(struct button,bool SoundEffects)
- // WHERE: button: struct returned by CreateButton
- // SoundEffects: if True then make a click noise, else not
- // NOTE: Does not change default color
- //
-
- #include <Screen.lib>
- #include <sound.lib>
-
- CreateButton(pText,pRow,pCol,pHeight,pWidth,pFore,pBack,p3D,pLines)
- {
- // initialize button structure
- strcpy(lButt.Text,pText);
- lButt.x0 = pCol; lButt.y0 = pRow;
- lButt.x1 = pCol + pWidth - 1; lButt.y1 = pRow + pHeight - 1;
- lButt.Fore = pFore; lButt.Back = pBack;
- lButt.shade = p3D ? SHADOW : 0; lButt.lines = pLines;
- lButt.TextRow = pRow + pHeight / 2;
- lButt.TextCol = pCol + (pWidth - strlen(pText))/2
- // get background if 3D
- if ( p3D ) {
- ReadCharacter(pRow,pCol,lButt.attribute);
- }
- // draw the initial button
- lSaveFore = slForeColor; lSaveBack = slBackColor;
- TextBox(pRow,pCol,lButt.y1,lButt.x1,pFore,pBack,pLines | lButt.shade);
- ScrWrite(pText,lButt.TextRow,lButt.TextCol);
- slForeColor = lSaveFore; slBackColor = lSaveBack;
- // return the structure to use later
- return lButt;
- }
-
- PushButton(pButt,pSound)
- {
- lSaveFore = slForeColor; lSaveBack = slBackColor;
- if ( pButt.shade ) {
- SetAttribute(pButt.attribute);
- Scroll(0,pButt.y0,pButt.x0,pButt.y1+1,pButt.x1+2);
- TextBox(pButt.y0+1,pButt.x0+2,pButt.y1+1,pButt.x1+2,
- pButt.Fore,pButt.Back,pButt.lines);
- ScrWrite(pButt.Text,pButt.TextRow+1,pButt.TextCol+2);
- if ( pSound ) sound(250,0);
- suspend(300);
- SetAttribute(pButt.attribute);
- Scroll(0,pButt.y0,pButt.x0,pButt.y1+1,pButt.x1+2);
- TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
- pButt.Fore,pButt.Back,pButt.lines|SHADOW);
- ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
- if ( pSound ) sound(300,0);
- } else {
- TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
- pButt.Back,pButt.Fore & 0x7,pButt.lines);
- ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
- if ( pSound ) sound(250,0);
- suspend(300);
- TextBox(pButt.y0,pButt.x0,pButt.y1,pButt.x1,
- pButt.Fore,pButt.Back,pButt.lines);
- ScrWrite(pButt.Text,pButt.TextRow,pButt.TextCol);
- if ( pSound ) sound(300,0);
- }
- slForeColor = lSaveFore; slBackColor = lSaveBack;
- }
-